package com.zjw.concurrency.juc.lock.reentrantLock;

import java.util.concurrent.locks.ReentrantLock;

public class CinemaBookSeat {

    private static ReentrantLock lock = new ReentrantLock();

    public static void main(String[] args) {
        new Thread(()->{
            new CinemaBookSeat().book();
        }).start();
        new Thread(()->{
            new CinemaBookSeat().book();
        }).start();
        new Thread(()->{
            new CinemaBookSeat().book();
        }).start();
        new Thread(()->{
            new CinemaBookSeat().book();
        }).start();
    }

    public void book(){
        lock.lock();
        try {
            System.out.println("线程"+Thread.currentThread().getName()+"开始预定座位");
        }finally {
            lock.unlock();
            System.out.println("线程"+Thread.currentThread().getName()+"预定完了座位");
        }
    }
}
